
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><?php echo $title;?></title>
    <!-- 设置缩放 -->
    <meta name="viewport" content="minimal-ui,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <!-- IOS中禁用将数字识别为电话号码/忽略Android平台中对邮箱地址的识别 -->
    <meta name="format-detection" content="telephone=no" />
    <!-- windows phone 点击无高光 -->
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- icon -->
    <link rel="shortcut icon" href="<?php echo ADMIN_ICO_PIC;?>" type="image/x-icon"/>
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="<?php echo SYS_LINK;?>admin/css/content.css?v=<?php echo V_CSSJS;?>" />
    <style>
        .cenbox{display: inline-block;}
        .classBox{padding-left: 35px}
        .cenbox .sys_e{padding: 5px 0;height:25px;min-width:700px;line-height: 25px;border-bottom: 1px solid #ddd;}
        .cenbox .sys_e:first-child{border-top: 1px solid #ddd;}
        .sys_e input.input250 {border: none;border-left: 1px solid #ddd;width: 250px;height: 30px;float: right;margin-top: -3px;
            padding: 0 10px;color: #333;}
        .sys_e input.input150 {border: none;border-left: 1px solid #ddd;width: 150px;height: 30px;float: right;margin-top: -3px;
            padding: 0 10px;color: #333;}
        .sys_e label{text-align: left;}
        .form_item {min-height: auto;}
        .form_item textarea{height:100px;}
    </style>
</head>
<?php
$userLevel = getUserLevel();
$mouldCode = isset($mouldCode) ? $mouldCode : '';
$sortFlag = isset($sortFlag) ? $sortFlag : '';
$tableId = isset($tableId) ? $tableId : '';
$titleH = $sortFlag == 1 ? '菜单表字段' : ($tableId == 1 ? $mouldCode.'表字段' : $mouldCode.'_detail表字段');
$titleH .= '修改';
?>
<body>
<div class="con_box">
    <div class="titleH18"><?php echo $titleH;?></div>
    <form class="form_box">
        <input type="hidden" name="id" value="<?php echo $info['id'];?>">
        <input type="hidden" name="mould_code" value="<?php echo $mouldCode;?>">
        <input type="hidden" name="sortflag" value="<?php echo $sortFlag;?>">
        <input type="hidden" name="tableid" value="<?php echo $tableId;?>">
        <div class="form_item">
            <label>字段名称</label>
            <input type="text" name="fieldname" value="<?php echo $info['fieldname'];?>" autocomplete="off" placeholder="请输入">
            <i class="hint">* 必填，字段中文昵称/注释</i>
        </div>
        <div class="form_item">
            <label>字段标识</label>
            <input type="text" name="fieldcode" value="<?php echo $info['fieldcode'];?>" autocomplete="off" placeholder="字母开头且字母/数字/下划线组成">
            <i class="hint">* (必填)必须是小写字母开头</i>
        </div>
        <div class="form_item">
            <label>字段类型</label>
            <select name="fieldtype" class="fieldtype">
                <?php
                if(isset($fieldTypeArr)){
                    foreach($fieldTypeArr as $k=>$v){
                        $selected = $k == $info['fieldtype'] ? 'selected="selected"' : '';
                        echo '<option value="'.$k.'" '.$selected.'>'.$v.'</option>';
                    }
                }
                ?>
            </select>
            <i class="hint">* (必选)</i>
        </div>
        <div class="form_item">
            <label>字段长度</label>
            <input type="number" name="fieldlong" class="fieldlong" value="<?php echo $info['fieldlong'];?>" autocomplete="off" placeholder="整数">
            <i class="hint">* (选填)文本/整数/货币/密码类型有效</i>
        </div>
        <div class="form_item">
            <label>字段默值</label>
            <input type="text" name="fieldval" value="<?php echo $info['fieldval'];?>" autocomplete="off" placeholder="可不填">
            <i class="hint">* (选填)字段默认值</i>
        </div>
        <div class="form_item">
            <label>字段规则<br><br><br><br><br><br></label>
            <textarea name="fieldrule" class="fieldrule" placeholder="富文本框时为菜单类型(1:简,2:全)；&#10;单选多选下拉时选项:选项A=值1|选项B=值2；&#10;唯一码时字符串前缀(可为空)；&#10;图片裁剪：宽|高；&#10;多图/多文件上传:个数；&#10;图片上传同时个数和裁剪限制:个数=宽|高"><?php echo $info['fieldrule'];?></textarea>
            <i class="hint">* (选填)<br><br><br><br><br></i>
        </div>
        <div class="form_item">
            <label>其他规则<br><br><br><br><br><br></label>
            <textarea name="fieldrule2" class="fieldrule2" placeholder="图片上传生成多个缩略图规则:&#10;(宽=高|宽=高…)比如：200=200|250=250；&#10;"><?php echo $info['fieldrule2'];?></textarea>
            <i class="hint">* (选填)<br><br><br><br><br></i>
        </div>
        <div class="form_item">
            <label>裁剪类型</label>
            <?php
            $cutflag1 = $info['cutflag'] == 1 ? 'selected="selected"' : '';
            $cutflag2 = $info['cutflag'] == 2 ? 'selected="selected"' : '';
            $cutflag3 = $info['cutflag'] == 3 ? 'selected="selected"' : '';
            $cutflag4 = $info['cutflag'] == 4 ? 'selected="selected"' : '';
            $cutflag5 = $info['cutflag'] == 5 ? 'selected="selected"' : '';
            ?>
            <select name="cutflag" class="cutflag">
                <option value="0" >请选择</option>
                <option value="1" <?php echo $cutflag1;?>>宽高固定</option>
                <option value="2" <?php echo $cutflag2;?>>限宽不限高</option>
                <option value="3" <?php echo $cutflag3;?>>限高不限宽</option>
                <option value="4" <?php echo $cutflag4;?>>按照中心点</option>
                <option value="5" <?php echo $cutflag5;?>>智能裁剪</option>
            </select>
            <i class="hint">* (选填)图片裁剪时选择</i>
        </div>
        <div class="form_item">
            <label>原图处理</label>
            <?php
            $cuttype1 = $info['cuttype'] == 1 ? 'selected="selected"' : '';
            ?>
            <select name="cuttype" class="cuttype">
                <option value="0">不保存</option>
                <option value="1" <?php echo $cuttype1;?> >保存</option>
            </select>
            <i class="hint">* (选填)图片裁剪时选择</i>
        </div>
        <div class="form_item">
            <label>控件提示</label>
            <input type="text" name="fieldhint" value="<?php echo $info['fieldhint'];?>" autocomplete="off" placeholder="可为空">
            <i class="hint">* (选填)表单控件提示性信息</i>
        </div>
        <div class="form_item">
            <label>控件大小</label>
            <input type="number" name="showwidth" value="<?php echo $info['showwidth'];?>" class="showwidth input100" > × <input type="number" name="showheight" value="<?php echo $info['showheight'];?>" class="showheight input100" >
            <i class="hint">* (必填) 控件展示位大小(高于30时显示多行文本框)</i>
        </div>
        <div class="form_item">
            <label>字段排序</label>
            <input type="number" name="viewseq" value="<?php echo $info['viewseq'];?>" autocomplete="off" placeholder="显示排序顺序" class="input100">
            <i class="hint">* (必填)必须正整数，显示排序顺序，越大越靠前，默认0</i>
        </div>
        <div class="form_item">
            <label>禁止输入</label>
            <?php
            $banflag1 = $info['banflag'] == 1 ? 'checked="checked"' : '';
            $banflag2 = $info['banflag'] == 2 ? 'checked="checked"' : '';
            ?>
            <label class="radio"><input type="radio" value="1" name="banflag" <?php echo $banflag1;?>>开启</label>
            <label class="radio"><input type="radio" value="2" name="banflag" <?php echo $banflag2;?>>关闭</label>
            <i class="hint">* (必选)是否禁止输入</i>
        </div>
        <div class="form_item" <?php if($sortFlag == 1 || $tableId == 2){echo 'style="display:none"';}?>>
            <label>展示位置</label>
            <?php
            $showflag1 = $info['showflag'] == 1 ? 'checked="checked"' : '';
            $showflag2 = $info['showflag'] == 2 ? 'checked="checked"' : '';
            ?>
            <label class="radio"><input type="radio" value="1" name="showflag" <?php echo $showflag1;?> >内容页</label>
            <label class="radio"><input type="radio" value="2" name="showflag" <?php echo $showflag2;?> >内容页+列表页</label>
            <label class="radio"><input type="number" name="tdwidth" value="<?php echo $info['tdwidth'];?>" autocomplete="off" placeholder="列宽" class="input50"></label>
            <i class="hint">* (必选)文章列表是否展示(列表展示设置列宽0不设置)</i>
        </div>
        <div class="form_item">
            <label>字段状态</label>
            <?php
            $status1 = $info['status'] == 1 ? 'checked="checked"' : '';
            $status2 = $info['status'] == 2 ? 'checked="checked"' : '';
            $status3 = $info['status'] == 3 ? 'checked="checked"' : '';
            ?>
            <label class="radio"><input type="radio" value="1" name="status" <?php echo $status1;?> >已启用</label>
            <label class="radio"><input type="radio" value="2" name="status" <?php echo $status2;?> >已停用</label>
            <label class="radio"><input type="radio" value="3" name="status" <?php echo $status3;?> >已隐藏</label>
            <i class="hint">* (必选)字段启用状态</i>
        </div>
        <div class="form_item classBox" >
            <div class="cenbox">
                <?php
                if(!empty($classList)) {
                    $detail = isset($info['detail']) ? $info['detail'] : array();
                    $classArr = array();
                    $descArr = array();
                    $ruleArr = array();
                    foreach($detail as $k=>$v){
                        $classArr[$v['menu_id']] = $v['menu_id'];
                        $descArr[$v['menu_id']] = $v['fielddesc'];
                        $ruleArr[$v['menu_id']] = $v['fieldclassrule'];
                    }
                    foreach($classList as $v){
                        $id = $v['id'];
                        $fontb = !$v['fid'] ? 'fontb' : '';
                        $level = $v['level']*2;
                        $str = str_pad("",$level, '-',STR_PAD_LEFT );
                        $checked = in_array($id, $classArr) ? 'checked="checked"' : '';
                        $desc = isset($descArr[$id]) && $descArr[$id] ? $descArr[$id] : '';
                        $rule = isset($ruleArr[$id]) && $ruleArr[$id] ? $ruleArr[$id] : '';
                        if($sortFlag == 1 || $v['mould_code'] == $mouldCode){
                            echo '<div class="sys_e">
                                    <label>
                                        <input type="checkbox" value="'.$id.'" name="open_menu_id['.$id.']" '.$checked.' />
                                        <span class="'.$fontb.'" title="'.$v["menuname"].'">'.$str.' '.mbSubstr($v["menuname"],0,20,'…').'</span>
                                    </label>
                                    <input type="text" name="open_classrule['.$id.']" value="'.$rule.'" class="input150" placeholder="(可不填)可覆盖字段规则" />
                                    <input type="text" name="open_classdesc['.$id.']" value="'.$desc.'" class="input250" placeholder="(可不填)字段描述,可覆盖“控件提示”" />
                            </div>';
                        }
                    }
                }
                ?>
            </div>
        </div>

        <div class="form_item">
            <label style="color:#ff7f77"> 编辑需保存 </label>
            <input type="button" id="sub_btn" value="提交保存" class="btn_base btn_back_sides btn_w300 btn_height35 btn_radius5">
        </div>
    </form>
</div>
</body>
<script language="javascript">
    var cssjsv = '<?php echo V_CSSJS;?>';
    var http_url = '<?php echo SYS_HOST;?>';
    var http_link = '<?php echo SYS_LINK;?>';
    var http_fix = '<?php echo SYS_URL_FIX;?>';
</script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/jquery.min.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/skin.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/common.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript">file_load('info');</script>
<script language="javascript">
    // 加载完毕后
    window.onload = function () {

    }

    // 选择字段类型时初始一部分值
    $(".fieldtype").change(function(){
        var types = $(this).val();
        var fieldlong = 200;
        var fieldrule = '';
        var showwidth = 280;
        var showheight = 30;
        if(types == 2){ // 富文本框
            fieldlong = '';
            fieldrule = 2;
            showwidth = 805;
            showheight = 400;
        }
        if(types == 10){ // 下拉框
            showwidth = 302;
        }
        if(types == 11 || types == 12 ){ // 单选多选
            showwidth = 15;
            showheight = 15;
        }
        $('.fieldlong').val(fieldlong);
        $('.fieldrule').val(fieldrule);
        $('.showwidth').val(showwidth);
        $('.showheight').val(showheight);
    })
    // 富文本时修改规则
    $(".fieldrule").keyup(function(){
        let rule = $(".fieldrule").val();
        let types = $(".fieldtype").val();
        if(types == 2 && rule == 1){
            $(".showwidth").val('630');
            $(".showheight").val('400');
        }
        if(types == 2 && rule == 2){
            $(".showwidth").val('805');
            $(".showheight").val('400');
        }
    })

    // 提交保存
    var flagSub = true;
    var addUrl = '<?php echo SYS_URL_PATH('admin_field_update');?>';
    $(function(){
        $('#sub_btn').on('click',function(){
            if(!flagSub){
                layer.msg('处理中……(禁止重复提交)');return false;
            }
            flagSub = false;
            var fromBox = $('.form_box');
            var param = getFormData(fromBox);
            param.append('subFlag', 'Y'); // 追加参数
            $.ajax({
                url:addUrl,
                dataType:'json',
                type:'POST',
                async: false,
                data: param,
                processData : false, // 使数据不做处理
                contentType : false, // 不要设置Content-Type请求头
                success: function(data){
                    flagSub = true;
                    if(data=='Y'){
                        layer.msg('修改成功');
                        setTimeout(function(){
                            parent.location.reload();
                        },2500);
                    }else{
                        layer.msg('操作失败_'+data);
                    }
                },
                error:function(response){
                    flagSub = true;
                    layer.msg('网络异常');
                    console.log('网络异常：'+response);
                }
            });
        })
    })
</script>
</html>